from brian import *
from brian.library.random_processes import *
from brian.library.synapses import  *
from MyConstants import *


class SuperNeuron:
    def init(self):
        return
    def add_rand_curr(self,rand):
        if rand:
            self.eqs+='''dIrand/dt = (mu-Irand)*invtau_rand+sigma*((2.*invtau_rand)**.5)*xi : uA*cm**-2
                    '''
        else:
            self.eqs+='''Irand = 0 *uA*cm**-2 : uA*cm**-2
                      '''
        
    def add_synapses(self,synapse,tau1,tau2=1*ms):
        if(synapse=='alpha'):
            self.eqs+=Equations('''dge/dt = -ge*invtau : siemens*metre**-2
                dgi/dt = -gi*invtau : siemens*metre**-2
                dipsp/dt = (gi-ipsp)*invtau : siemens*metre**-2
                depsp/dt = (ge-epsp)*invtau : siemens*metre**-2
                ''',invtau=1/tau1)
        elif(synapse=='exp'):
            self.eqs+=Equations('''
                dipsp/dt = -ipsp*invtau : siemens*metre**-2
                depsp/dt = -epsp*invtau : siemens*metre**-2
                ge = epsp
                gi = ipsp
                ''',invtau=1/tau1)
        elif(synapse=='biexp'):
            self.eqs+=Equations('''dge/dt = -ge*invtau2 :siemens*metre**-2
                depsp/dt = (invpeak*ge-epsp)*invtau1 :siemens*metre**-2
                dgi/dt = -gi*invtau2 :siemens*metre**-2
                dipsp/dt = (invpeak*gi-ipsp)*invtau1 :siemens*metre**-2  
                ''',invtau1=1/tau1,invtau2=1/tau2,invpeak = (tau2 / tau1) ** (tau1 / (tau2 - tau1)))
        else:
            self.eqs+='''ipsp = 0 *siemens*metre**-2:siemens*metre**-2
                epsp = 0 *siemens*metre**-2:siemens*metre**-2
                '''
    